home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_sharutils.idb / usr / freeware / bin / mail-files.z / mail-files
Text File  |  2000-04-13  |  2KB  |  89 lines

  1. #! /sbin/sh
  2. # Mail a list of files, as they are.
  3. # Copyright (C) 1990, 1995 Free Software Foundation, Inc.
  4. # Franτois Pinard <pinard@iro.umontreal.ca>, 1991.
  5.  
  6. package="sharutils"
  7. version="4.2.1"
  8.  
  9. progname=`echo $0 | sed -e 's,.*/,,'`
  10.  
  11. usage="\
  12. Usage: $progname [OPTION] DESTIN TYPE SUBJECT FILE ...
  13.  
  14. with OPTION in:
  15.       --help      display this help and exit
  16.       --version   output version information and exit
  17.  
  18.   -x              trace script"
  19.  
  20. trytext="Try \`$progname --help' for more information."
  21.  
  22. SLEEP=2
  23.  
  24. ### Decode the options.
  25.  
  26. while test $# -gt 0; do
  27.   case $1 in
  28.     -x) trace=-x; set -x; shift ;;
  29.     --v* ) echo "$progname - $package $version"; exit 0 ;;
  30.     --h* ) echo "$usage"; exit 0 ;;
  31.     -) break ;;
  32.     -*) echo "$trytext"; exit 1 ;;
  33.     *) break
  34.   esac
  35. done
  36.  
  37. if [ $# -lt 4 ]; then
  38.   echo "Too few arguments."
  39.   echo $trytext
  40.   exit 1
  41. fi
  42.  
  43. destin="$1"; shift
  44. type="$1"; shift
  45. subject="$1"; shift
  46.  
  47. maxcount=$#
  48. files="$*"
  49.  
  50. ### Mail all files, making a proper subject for each message.
  51.  
  52. ( if [ -f $destin ]; then
  53.     cat $destin
  54.   else
  55.      echo $destin
  56.   fi
  57. ) |
  58. ( total=0
  59.   while read destin; do
  60.     count=0
  61.     for file in $files; do
  62.       if [ ! -f $file ]; then
  63.     echo "$file not found"
  64.     continue
  65.       fi
  66.       count=`expr $count + 1`
  67.       if [ $maxcount = 1 ]; then
  68.     string="$type"
  69.       else
  70.     string="$type ($count/$maxcount)"
  71.       fi
  72.       echo "Mailing $string to $destin"
  73.       [ $total -ne 0 ] && sleep $SLEEP
  74.       /usr/sbin/Mail -s "$string: $subject" $destin < $file
  75.       total=`expr $total + 1`
  76.       [ $count -lt $maxcount ] && sleep $SLEEP
  77.     done
  78.   done
  79.   if [ $total -eq 0 ]; then
  80.     echo 'No message queued'
  81.   elif [ $total -eq 1 ]; then
  82.     echo 'Message queued'
  83.   else
  84.     echo "$count messages queued"
  85.   fi
  86. )
  87.  
  88. exit 0
  89.